home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 5 / Apprentice-Release5.iso / Source Code / Libraries / MacPNG Library 1.02 / pngMacSrc 1.02 / png.1 / ptot / tempfile.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-08-17  |  1.5 KB  |  84 lines  |  [TEXT/CWIE]

  1. /*
  2.  * tempfile.c
  3.  *
  4.  * Temporary file handline for ptot.
  5.  *
  6.  **********
  7.  *
  8.  * HISTORY
  9.  *
  10.  * 95-03-10 Created by Lee Daniel Crocker <lee@piclab.com>
  11.  *          <URL:http://www.piclab.com/piclab/index.html>
  12.  */
  13.  
  14. #include <stdlib.h>
  15. #include <stdio.h>
  16. #include <string.h>
  17.  
  18. #include "ptot.h"
  19.  
  20. #define DEFINE_ENUMS
  21. #include "errors.h"
  22.  
  23. extern PNG_STATE ps;
  24.  
  25. int
  26. create_tempfile(
  27.     int pass)
  28. {
  29.     char temp_name[FILENAME_MAX];
  30.  
  31.     ASSERT(pass >= 0 && pass < 7);
  32.     ASSERT(NULL == ps.tf[pass]);
  33.  
  34.     if (NULL == ps.tfnames[pass]) {
  35.         sprintf(temp_name, "pngpass%d.tmp", pass);
  36.         ps.tfnames[pass] = (char *)malloc(strlen(temp_name) + 1);
  37.         if (NULL == ps.tfnames[pass]) return ERR_MEMORY;
  38.         strcpy(ps.tfnames[pass], temp_name);
  39.     }
  40.     ps.tf[pass] = fopen(ps.tfnames[pass], "wb");
  41.     if (NULL == ps.tf[pass]) return ERR_WRITE;
  42.  
  43.     return 0;
  44. }
  45.  
  46. int
  47. open_tempfile(
  48.     int pass)
  49. {
  50.     ASSERT(pass >= 0 && pass < 7);
  51.     ASSERT(NULL != ps.tfnames[pass]);
  52.  
  53.     if (NULL != ps.tf[pass]) fclose(ps.tf[pass]);
  54.     ps.tf[pass] = fopen(ps.tfnames[pass], "rb");
  55.     if (NULL == ps.tf[pass]) return ERR_READ;
  56.  
  57.     return 0;
  58. }
  59.  
  60. void
  61. close_all_tempfiles(
  62.     void)
  63. {
  64.     int pass;
  65.  
  66.     for (pass = 0; pass < 7; ++pass) {
  67.         if (NULL != ps.tf[pass]) fclose(ps.tf[pass]);
  68.         ps.tf[pass] = NULL;
  69.     }
  70. }
  71.  
  72. void
  73. remove_all_tempfiles(
  74.     void)
  75. {
  76.     int pass;
  77.  
  78.     for (pass = 0; pass < 7; ++pass) {
  79.         if (NULL != ps.tf[pass]) fclose(ps.tf[pass]);
  80.         if (NULL != ps.tfnames[pass]) remove(ps.tfnames[pass]);
  81.     }
  82. }
  83.  
  84.